package com.lenovo.locationmanager;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * @ProjectName: GpsAutoTest
 * @Package: com.lenovo.gpsautotest.LocationManager
 * @ClassName: SvInfoAdapter
 * @Description: SvInfoAdapter类作用描述
 * @Author: kgzhou
 * @CreateDate: 2019/6/5 14:09
 * @UpdateUser: kgzhou
 * @UpdateDate: 2019/6/5 14:09
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class SvInfoAdapter extends RecyclerView.Adapter<SvInfoAdapter.VH> {

    private List<GpsSatellite> gpsSatellites;

    private StringBuilder builder = new StringBuilder();


    public SvInfoAdapter(List<GpsSatellite> gpsSatellites) {
        this.gpsSatellites = gpsSatellites;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        // 实例化展示的view
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.svinfo, parent,
                false);
        return new VH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        GpsSatellite gpsSatellite = gpsSatellites.get(position);
        holder.snr.setText(gpsSatellite.getmSnr() + "");
        holder.prn.setText(gpsSatellite.getmPrn() + "");
        String elevation = String.valueOf(gpsSatellite.getmElevation());
        if (elevation.equals("0") || elevation.equals("-90")) {
            holder.elevation.setText("-");
        } else {
            holder.elevation.setText(elevation);
        }
        float azimuth = gpsSatellite.getmAzimuth();
        if (azimuth == 0.0f) {
            holder.azimuth.setText("-");
        } else {
            holder.azimuth.setText(String.valueOf(azimuth));
        }
        holder.flags.setText(Utils.getSatelliteFlags(gpsSatellite));
    }

    @Override
    public int getItemCount() {
        return gpsSatellites.size();
    }

    //② 创建ViewHolder
    public class VH extends RecyclerView.ViewHolder {
        public TextView prn;
        public TextView snr;
        public TextView elevation;
        public TextView azimuth;
        public TextView flags;

        public VH(@NonNull View itemView) {
            super(itemView);
            prn = itemView.findViewById(R.id.tv_prn);
            snr = itemView.findViewById(R.id.tv_snr);
            elevation = itemView.findViewById(R.id.tv_elevation);
            azimuth = itemView.findViewById(R.id.tv_azimuth);
            flags = itemView.findViewById(R.id.tv_flags);
        }
    }
}
